package com.wangzhixuan.service.impl;

import com.wangzhixuan.model.Productionimg;
import com.wangzhixuan.mapper.ProductionimgMapper;
import com.wangzhixuan.service.IProductionimgService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户角色 服务实现类
 * </p>
 *
 * @author zhixuan.wang
 * @since 2017-06-24
 */
@Service
public class ProductionimgServiceImpl extends ServiceImpl<ProductionimgMapper, Productionimg> implements IProductionimgService {

	@Override
	public int deleteImgsByProductKey(String dir,String productKey) {
		Map<String, Object> columnMap=new HashMap<String, Object> ();
        columnMap.put("man_product_key",productKey);
        List<Productionimg>  proimgList=this.selectByMap(columnMap);
        if(proimgList==null || proimgList.size()==0){
        	return 0;
        }
	    for(Productionimg pimg:proimgList){
		   File file=new File(dir+pimg.getManImg());
		   if(file.isFile() && file.exists()){
			   file.delete();
		   }
		   this.deleteById(pimg.getId());
	   }
	   return 1;
	}
}
